from flask import Flask ,session
from flask_script import Manager
from flask_sqlalchemy import SQLAlchemy
import redis
from flask_wtf.csrf import CSRFProtect
from flask_session import Session

app = Flask(__name__)
# 创建manager与app进行关联
manager = Manager(app)
# 需求：可以通过命令行在运行的时候指定运行的端口
class Config(object):
    """配置信息"""
    REDIS_HOST = "127.0.0.1"
    REDIS_PORT = 6379
    REDSI_PASSWORD = "123456"
    SECRET_KEY = "EjpNVSNQTyGi1VvWECj9TvC/+kq3oujee2kTfQUs8yCM6xX9Yjq52v54g+HVeeee"

    DEBUG = True
    SQLALCHEMY_DATABASE_URI = "mysql+mysqlconnector://root:mysql@127.0.0.1:3306/information9"
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    ...
    # flask_session的配置信息
    SESSION_TYPE = "redis"  # 指定 session 保存到 redis 中
    SESSION_USE_SIGNER = True  # 让 cookie 中的 session_id 被加密签名处理
    SESSION_REDIS = redis.StrictRedis(host=REDIS_HOST, port=REDIS_PORT,password=REDSI_PASSWORD)  # 使用 redis 的实例
    PERMANENT_SESSION_LIFETIME = 86400*2

app.config.from_object(Config)
db = SQLAlchemy(app)
redis_store= redis.StrictRedis(host=Config.REDIS_HOST,port=Config.REDIS_PORT,password=Config.REDSI_PASSWORD)
CSRFProtect(app)
Session(app)


@app.route('/')
def index():
    session["hhh"] = "test"
    return 'index3333333333'


if __name__ == '__main__':
    # 使用 manager 去运行
    manager.run()
